iT邦幫忙

2021 iThome 鐵人賽

DAY 23
0

這篇是繼上篇另外做添加管理權限
權限 @Display_name 111110
https://ithelp.ithome.com.tw/upload/images/20211005/20140165HqgbG8Jj16.png
https://ithelp.ithome.com.tw/upload/images/20211005/20140165WwCIhnc3Xv.png

DO
$do$
BEGIN 
IF EXISTS(SELECT uid FROM group_right WHERE uid='{uid}') THEN UPDATE group_right SET add_message_right={bool(int(right[0]))}, delete_message_right={bool(int(right[1]))},view_right={bool(int(right[2]))},add_buyer_right={bool(int(right[3]))},delete_buyer_right={bool(int(right[4]))},allow_changeright_right={bool(int(right[5]))} WHERE uid='{uid}'; 
ELSE INSERT INTO group_right (uid,add_message_right,delete_message_right,view_right,add_buyer_right,delete_buyer_right,allow_changeright_right) VALUES ('{uid}',{bool(int(right[0]))},{bool(int(right[1]))},{bool(int(right[2]))},{bool(int(right[3]))},{bool(int(right[4]))},{bool(int(right[5]))}); 
END IF; 
END 
$do$"
if(event.message.text[:2:]=="權限" and rights[5]):
    if not event.message.mention is None:
        for user in event.message.mention.mentionees:
            uid=user.user_id
        lastLength=3
        text=event.message.text[3::]
        right=text[text.find(" ",lastLength+1)+1:len(text):]
        cursor = conn.cursor()
        cursor.execute(f"DO $do$ BEGIN IF EXISTS(SELECT uid FROM group_right WHERE uid='{uid}') THEN UPDATE group_right SET add_message_right={bool(int(right[0]))}, delete_message_right={bool(int(right[1]))},view_right={bool(int(right[2]))},add_buyer_right={bool(int(right[3]))},delete_buyer_right={bool(int(right[4]))},allow_changeright_right={bool(int(right[5]))} WHERE uid='{uid}'; ELSE INSERT INTO group_right (uid,add_message_right,delete_message_right,view_right,add_buyer_right,delete_buyer_right,allow_changeright_right) VALUES ('{uid}',{bool(int(right[0]))},{bool(int(right[1]))},{bool(int(right[2]))},{bool(int(right[3]))},{bool(int(right[4]))},{bool(int(right[5]))}); END IF; END $do$")
        conn.commit()
        cursor.close()
        message=TextSendMessage("權限已變更")
        line_bot_api.reply_message(event.reply_token,message)

上一篇
DAY 22 完成管理功能與權限
下一篇
DAY 24 優化檢視團購訊息
系列文
LINE Messaging API SDK for Python 實現群組團購輔助機器人30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言